import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static int getAroundBomb(int[][] bomb, int i, int j) {
		int count = 0;
		int rudI;
		int rudJ;

		rudI = i - 1;
		for(int m = 0; m < 3; m++) {
			rudJ = j - 1;
			for(int n = 0; n < 3; n++) {
				if(rudI >= 0 && rudI < bomb.length && rudJ >= 0 && rudJ < bomb.length) {
					if(bomb[rudI][rudJ] == 1)
						count++;
				}
				rudJ++;
			}
			rudI++;
		}
		
		if(bomb[i][j] == 1)
			count--;
		
		return count;
	}
	public static String getResult(int[][] bomb) {
		String result = "";
		
		for(int i = 0; i < bomb.length; i++) {
			for(int j = 0; j < bomb[i].length; j++) {
				if(bomb[i][j] == 0) {
					result += getAroundBomb(bomb, i, j);
				} else {
					result += "0";
				}
				
				if(j < bomb[j].length - 1)
					result += " ";
			}
			result += "\n";
		}
		
		return result;
	}
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder output;
		String input;
		String[] spInput;
		int n;
		int[][] bomb;
		
		while((input = br.readLine()) != null) {
			spInput = input.split(" ");
			n = Integer.parseInt(spInput[0]);
			bomb = new int[n][n];
			for(int i = 0; i < bomb.length; i++) {
				input = br.readLine();
				spInput = input.split(" ");
				for(int j = 0; j < bomb[i].length; j++) {
					bomb[i][j] = Integer.parseInt(spInput[j]);
				}
			}
			
			output = new StringBuilder();
			
			output.append(getResult(bomb));
			
			System.out.print(output);
		}
	}
}